package com.redog;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


/**
 *被增强类没有异常 @AfterThrowing不会执行
 *
 * 被增强类有异常  @AfterThrowing会执行，@AfterReturning，@Around环绕后通知不会执行
 */





@Component
@Aspect
@Order(2)
public class UserProxy {

    //因为切入点表达式相同，所以可以抽取相同切入点
    @Pointcut(value = "execution(* com.redog.User.Add(..))")
    public void poincut(){

    }



    //前置通知
    @Before(value = "poincut()")
    public void before(){
        System.out.println("before......");
    }



    @After(value = "execution(* com.redog.User.Add(..))")
    public void after(){
        System.out.println("After....");
    }


    @AfterThrowing(value = "execution(* com.redog.User.Add(..))")
    public void afterThrowing(){
        System.out.println("AfterThrowing......");
    }

    @AfterReturning(value = "execution(* com.redog.User.Add(..))")
    public void afterReturning(){
        System.out.println("AfterReturning......");
    }
    @Around(value = "execution(* com.redog.User.Add(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {

        System.out.println("环绕之前........."); //被增强的方法执行
        proceedingJoinPoint.proceed();
        System.out.println("环绕之后.........");
    }


}
